package com.gsbelarus.gedemin.income.table;

import android.content.Context;

import com.gsbelarus.gedemin.income.R;
import com.gsbelarus.gedemin.income.adapter.ClientsListAdapter;

public class ClientsTable {

    private int id;
    private String name;
    private long paidSum;
    private long planSum;
    private int percent = 0;
    private int resourceImage;

    private int renderingMod = ClientsListAdapter.ALL_VISIBLE;

    private int onYear = 2000;
    private int onMonth = 1;
    private int onDay = 1;

    public ClientsTable(int id, String name, long paidSum, long planSum) {
        this.id = id;
        this.name = name;
        this.paidSum = paidSum;
        this.planSum = planSum;

        calculatePercent();
        choiceImage();
    }

    public ClientsTable(int id, long paidSum, long planSum) {
        this.id = id;
        this.paidSum = paidSum;
        this.planSum = planSum;

        calculatePercent();
        choiceImage();
    }

    /**
     * используется для экрана Поступления
     */
    public ClientsTable(int id, String name, long paidSum) {
        this.id = id;
        this.name = name;
        this.paidSum = paidSum;
    }


    public ClientsTable(int id, String name, long paidSum, long planSum, int Y, int M, int D) {
        this.id = id;
        this.name = name;
        this.paidSum = paidSum;
        this.planSum = planSum;
        this.onYear = Y;
        this.onMonth = M;
        this.onDay = D;

        calculatePercent();
        choiceImage();
    }

    public ClientsTable(int id, String name, long paidSum, long planSum, int Y, int M) {
        this.id = id;
        this.name = name;
        this.paidSum = paidSum;
        this.planSum = planSum;
        this.onYear = Y;
        this.onMonth = M;

        calculatePercent();
        choiceImage();
    }

    public ClientsTable(int id, String name, long paidSum, long planSum, int Y) {
        this.id = id;
        this.name = name;
        this.paidSum = paidSum;
        this.planSum = planSum;
        this.onYear = Y;

        calculatePercent();
        choiceImage();
    }



    public ClientsTable(int id,  long paidSum, long planSum, int Y, int M, int D) {
        this.id = id;
        this.paidSum = paidSum;
        this.planSum = planSum;
        this.onYear = Y;
        this.onMonth = M;
        this.onDay = D;

        calculatePercent();
        choiceImage();
    }

    public ClientsTable(int id,  long paidSum, long planSum, int Y, int M) {
        this.id = id;
        this.paidSum = paidSum;
        this.planSum = planSum;
        this.onYear = Y;
        this.onMonth = M;

        calculatePercent();
        choiceImage();
    }

    public ClientsTable(int id,   long paidSum, long planSum, int Y) {
        this.id = id;
        this.paidSum = paidSum;
        this.planSum = planSum;
        this.onYear = Y;

        calculatePercent();
        choiceImage();
    }

    private void calculatePercent() {
        percent = 0;
        if (planSum != 0) {
            percent = (int) (paidSum * 100 / planSum);
        }
    }

    public void convertMonth(Context context) {
        String[] ArrayDoW = context.getResources().getStringArray(R.array.month_list_values);
        if (id >= 1 && id <= 12) {
            name = ArrayDoW[id - 1];
        }
    }

    public void convertMonthYear(Context context, int year) {
        String[] ArrayDoW = context.getResources().getStringArray(R.array.month_list_values);
        if (id >= 1 && id <= 12) {
            name = ArrayDoW[id - 1];
            if (year > 0)
                name = name + " " + String.valueOf(year);
        }
    }

    public void choiceImage() {
        if (percent < 20)
            resourceImage = R.drawable.percent1;
        else if (percent < 40)
            resourceImage = R.drawable.percent2;
        else if (percent < 60)
            resourceImage = R.drawable.percent3;
        else if (percent < 80)
            resourceImage = R.drawable.percent4;
        else if (percent < 100)
            resourceImage = R.drawable.percent5;
        else if (percent >= 100)
            resourceImage = R.drawable.percent6;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getPaidSum() {
        return paidSum;
    }

    public void setPaidSum(long paidSum) {
        this.paidSum = paidSum;
    }

    public long getPlanSum() {
        return planSum;
    }

    public void setPlanSum(long planSum) {
        this.planSum = planSum;
    }

    public int getPercent() {
        return percent;
    }

    public void setPercent(int percent) {
        this.percent = percent;
    }

    public int getResourceImage() {
        return resourceImage;
    }

    public int getRenderingMod() {
        return renderingMod;
    }

    public void setRenderingMod(int renderingMod) {
        this.renderingMod = renderingMod;
    }

    public int getOnYear() {
        return onYear;
    }

    public int getOnMonth() {
        return onMonth;
    }

    public int getOnDay() {
        return onDay;
    }
}
